package com.dave.gd.core.common.globalsession.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dave.gd.core.common.globalsession.manager.SessionManager;

@SuppressWarnings("serial")
public class LogOffServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        // servlet方式输出页面
        // 设置页面字符集
        response.setContentType(CONTENT_TYPE);
        String sessionId = request.getParameter("sessionId");
        request.getSession().invalidate();// 调用GlobalHttpSession的invalidate方法使session失效
        SessionManager sm = new SessionManager();
        sm.deleteSessionIndex(sessionId);
        response.sendRedirect("login.jsp");
    }
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        doGet(req, resp);
    }
    
}
